
package com.dps.omc.action;

import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dps.omc.model.UserBizType;
import com.dps.omc.service.IUserBizTypeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dps.common.domain.view.BizData4Page;
import com.dps.common.utils.IdGenerator;
import com.dps.common.utils.JsonResult;
import com.dps.common.utils.PageParam;
import com.dps.common.utils.Constants;

@Controller
public class UserBizTypeAction extends AbstractAdminController<IUserBizTypeService>{

    @Autowired
    private IUserBizTypeService userBizTypeService;
    
    @RequestMapping(value="/userbiztype/list")
    public String list(UserBizType userBizType, ModelMap model, PageParam pageParam, HttpServletRequest request, HttpServletResponse response){

        //获取参数
    	Map<String, Object> conditions = getQueryMap(userBizType); 	
    	BizData4Page<UserBizType> pageCtx = doPage(model, conditions, pageParam);
    	model.addAttribute("userBizType", userBizType);
    	return "/module/userbiztype/list";
    }    
    
    @RequestMapping(value="/userbiztype/add")
    public String add(ModelMap model,HttpServletRequest request,HttpServletResponse response){

    	model.addAttribute("userBizType", new UserBizType());
        return "module/userbiztype/edit";
    }    
    
    @RequestMapping(value="/userbiztype/edit")
    public String edit(String id,ModelMap model,HttpServletRequest request,HttpServletResponse response){
    	
    	UserBizType userBizType = userBizTypeService.fetch(id);
    	model.addAttribute("userBizType", userBizType);
        return "module/userbiztype/edit";
    }    
    
    @RequestMapping(value="/userbiztype/save")
    @ResponseBody
    public String save(HttpServletRequest request,UserBizType userBizType){
		boolean isAddNew = StringUtils.isBlank(userBizType.getId())?true:false;
		if(isAddNew)
		{
			userBizType.setId(IdGenerator.createNewId());
			userBizTypeService.add(userBizType);
		}
		else
		{
			userBizTypeService.update(userBizType);
		}
        return JsonResult.saveSuccessClose(Constants.MAIN_TAB).toString();
    }    
    
    @RequestMapping(value="/userbiztype/delete")
    @ResponseBody
    public String delete(String ids,HttpServletRequest request){
    	
    	userBizTypeService.deleteByIds(ids);
    	return JsonResult.DELETE_SUCCESS.toString();
    }       
	
    protected Map getQueryMap(UserBizType userBizType)
    {
    	Map<String, Object> conditions = new HashMap();
    	
		conditions.put("userId", userBizType.getUserId());		
		conditions.put("userName", userBizType.getUserName());		
		conditions.put("realName", userBizType.getRealName());		
		conditions.put("bizTypeId", userBizType.getBizTypeId());		
		conditions.put("bizType", userBizType.getBizType());		
		conditions.put("bizTypeName", userBizType.getBizTypeName());		
		conditions.put("createDate", userBizType.getCreateDate());		
		conditions.put("createrId", userBizType.getCreaterId());		
		conditions.put("createrName", userBizType.getCreaterName());		
    	return conditions;
    }

    @Override
    protected IUserBizTypeService getMainService() {
        return userBizTypeService;
    }

    @Override
    protected String getMainObjName() {
        return "userbiztype";
    }

    @Override
    protected String getViewTitle() {
        return "userbiztype";
    }
}
